package com.bookmanger.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.bookmanger.entity.Order;
import com.bookmanger.entity.dto.BookBorrowCountDTO;
import com.bookmanger.entity.dto.OrderRankDTO;
import com.bookmanger.entity.select.OrderBookListDTO;
import com.bookmanger.entity.vo.BookCategoryCountVO;
import com.bookmanger.entity.vo.OrderBookListVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author huangfuhao
 * @Date 2024/10/26
 */
@Mapper
public interface OrderMapper extends BaseMapper<Order> {
    List<OrderBookListVo> getOrderBookList(@Param("orderBookListDTO") OrderBookListDTO orderBookListDTO,
                                           @Param("pageOffset") Integer pageOffset,
                                           @Param("size") Integer size);

    Long getOrderBookListCount(@Param("orderBookListDTO") OrderBookListDTO orderBookListDTO);

    /**
     * 查询借阅次数最多的图书排行榜
     *
     * @return List<BookBorrowCountDTO> 借阅次数最多的图书排行榜
     */
    @Select("SELECT book_id AS bookId,COUNT(book_id) AS borrowCount " +
            "FROM book_order " +
            "GROUP BY book_id " +
            "ORDER BY borrowCount DESC")
    List<BookBorrowCountDTO> getTopBorrowedBooks();

    List<BookCategoryCountVO> getOrderBookCategoryCount();
}

